package com.freewater.parking.domain.parking;

import com.freewater.parking.domain.common.DomainEvent;
import com.freewater.parking.domain.common.PlateNumber;
import org.apache.commons.lang3.Validate;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 已付费事件
 */
public class PaidEvent implements DomainEvent {
    /**
     * 车牌号
     */
    private final PlateNumber plateNumber;
    /**
     * 支付时间
     */
    private final LocalDateTime payTime;
    /**
     * 支付金额
     */
    private final int amount;
    /**
     * 入场时间
     */
    private final LocalDateTime checkInTime;

    public PaidEvent(PlateNumber plateNumber,
                     LocalDateTime payTime,
                     int amount,
                     LocalDateTime checkInTime) {
        Validate.notNull(plateNumber, "车牌号不能为空");
        Validate.notNull(payTime, "支付时间不能为空");
        Validate.isTrue(amount >= 0, "支付金额不能为负");
        Validate.notNull(checkInTime, "车辆入场时间不能为空");
        this.plateNumber = plateNumber;
        this.payTime = payTime;
        this.amount = amount;
        this.checkInTime = checkInTime;
    }

    @Override
    public LocalDateTime occurAt() {
        return this.payTime;
    }

    /**
     * 获取车牌号
     *
     * @return 车牌号
     */
    public PlateNumber getPlateNumber() {
        return plateNumber;
    }

    /**
     * 获取支付时间
     *
     * @return 支付时间
     */
    public LocalDateTime getPayTime() {
        return payTime;
    }

    /**
     * 获取支付金额
     *
     * @return 支付金额
     */
    public int getAmount() {
        return amount;
    }

    /**
     * 获取入场时间
     *
     * @return 入场时间
     */
    public LocalDateTime getCheckInTime() {
        return checkInTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PaidEvent paidEvent = (PaidEvent) o;
        return amount == paidEvent.amount &&
                Objects.equals(plateNumber, paidEvent.plateNumber) &&
                Objects.equals(payTime, paidEvent.payTime) &&
                Objects.equals(checkInTime, paidEvent.checkInTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(plateNumber, payTime, amount, checkInTime);
    }
}
